package com.xfz.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


import java.util.Arrays;
//面向切面编程

@Component
@Aspect
public class ServiceAdvice {
    @Pointcut("execution(* com.xfz.service.UserService.*(..))")
    public void myPoint() {

    }

    @Before("ServiceAdvice.myPoint()")
    public void beforService(JoinPoint joint) {
        System.out.println("准备执行" + joint.getSignature().getName() + "");
    }

    @AfterReturning("ServiceAdvice.myPoint()")
    public void afterService(JoinPoint joint) {
        System.out.println("成功执行" + joint.getSignature().getName() + "");
    }


    @Pointcut("execution(* org.springframework.jdbc.core.JdbcTemplate.*(..))")
    public void dbPoint() {

    }

    @Before("ServiceAdvice.dbPoint()")
    public void beforSql(JoinPoint joint) {
        System.out.println("即将执行" + joint.getArgs()[0]);
    }
}
